//
//  SettingFootView.swift
//  swiftProject
//
//  Created by ZhangSai on 2021/6/10.
//

import UIKit

protocol SettingFootDelegate:class {
    func homeViewAcrionDelegate(actonType:HomeViewActonType)
}

class SettingFootView: UIView {

    weak var delegate:SettingFootDelegate?

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        self.addSubview(self.titleLab)
        self.addSubview(self.imageView)
        self.addSubview(self.coutactUS)
        self.addSubview(self.messageLab)
        self.addSubview(self.privacyView)

        self.titleLab.snp.makeConstraints { (make) in
            make.top.equalTo(self.snp.top).offset(43)
            make.left.equalTo(self.snp.left).offset(15)
            make.height.equalTo(20)
        }
        self.imageView.snp.makeConstraints { (make) in
            make.top.equalTo(self.titleLab.snp.bottom).offset(15)
            make.left.equalTo(self.snp.left).offset(15)
            make.height.equalTo(52)
            make.width.equalTo(52)
        }
        self.coutactUS.snp.makeConstraints { (make) in
            make.top.equalTo(self.snp.top).offset(54)
            make.right.equalTo(self.snp.right).offset(-15)
            make.height.equalTo(20)
            let width = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_Contact).getWidth(UIFont.systemFont(ofSize: 14)) + 20
            make.width.equalTo(width)
        }
        self.messageLab.snp.makeConstraints { (make) in
            make.top.equalTo(self.titleLab.snp.bottom).offset(19)
            make.left.equalTo(self.imageView.snp.right).offset(12)
            make.left.equalTo(self.snp.right).offset(-15)
        }
        self.privacyView.snp.makeConstraints { (make) in
            make.top.equalTo(self.imageView.snp.bottom).offset(70)
            make.left.equalTo(self.snp.left).offset(15)
            make.right.equalTo(self.snp.right).offset(-15)
            make.height.equalTo(24)
            make.centerX.equalTo(self.snp.centerX)
        }
    }
    
    @objc func clickCoutactUS() {
        self.delegate?.homeViewAcrionDelegate(actonType: HomeViewActonType.Home_CoutactUSType)
    }
    
    func clickAgreementAction() {
        self.delegate?.homeViewAcrionDelegate(actonType: HomeViewActonType.Home_AgreemenType)
    }
    
    lazy var titleLab:UILabel = {
        let titleLab = UILabel.init()
        titleLab.font = UIFont.boldSystemFont(ofSize: 17)
        titleLab.textColor = UIColor.init(hexString: "#1C1C1C")
        titleLab.text = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_APPName)
        return titleLab;
    }()
    lazy var imageView:UIImageView = {
        let imageView = UIImageView.init(image: UIImage.init(named: "launch-4"))
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()
    lazy var coutactUS:UIButton = {
        let coutactUS = UIButton.init(type: .custom)
        coutactUS.setImage(UIImage.init(named: "login_phone"), for: .normal)
        coutactUS.setTitle(ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_Contact), for: .normal)
        coutactUS.setTitleColor(UIColor.init(named: "#424242"), for: .normal)
        coutactUS.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        coutactUS.addTarget(self, action: #selector(clickCoutactUS), for: .touchUpInside)
        coutactUS.titleLabel?.textAlignment = .center
        return coutactUS
    }()
    lazy var messageLab:UILabel = {
        let messageLab = UILabel.init()
        messageLab.font = UIFont.systemFont(ofSize: 12)
        messageLab.textColor = UIColor.init(hexString: "#777777")
        messageLab.numberOfLines = 0
        
        let text = NSMutableAttributedString.init(string: ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_APPMessage))
        text.yy_color = UIColor.init(hexString: "#777777")
        text.yy_font = UIFont.systemFont(ofSize: 12)
        
        let paragraphStyle = NSMutableParagraphStyle.init()
        paragraphStyle.lineSpacing = 5
        text.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSRange.init(location: 0, length: ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_APPMessage).count))
        messageLab.attributedText = text
        return messageLab
    }()
    lazy var privacyView:YYLabel = {
        let privacyView = YYLabel.init()
        let str = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_serveAgreement)
        let text = NSMutableAttributedString.init(string: str)
        text.yy_color = UIColor.init(hexString: "#717171")
        text.yy_alignment = .center
        text.addAttribute(.underlineStyle, value:  NSUnderlineStyle.single, range: NSRange.init(location: 0, length: str.count))
        text.yy_setTextHighlight(NSRange.init(location: 0, length: str.count), color: UIColor.init(hexString: "#4C4C4C"), backgroundColor: UIColor.clear) { (containerView, text, range, rect) in
            self.clickAgreementAction()
        }
        return privacyView
    }()
}
